using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Script.UI
{
    public class TipsWnd : MonoSingle<TipsWnd>
    {
        public Text text;
        public List<Transform> childList;


        public override void OnAwake()
        {
            var count = transform.childCount;
            for (int i = 0; i < count; i++)
            {
                childList.Add(transform.GetChild(i));
            }
        }

        public void Refresh()
        {
            
        }

        public void RefreshWithWaringInfo(UI_MainWnd.TipsInfo info)
        {
            foreach (var tip in childList)
            {
                tip.gameObject.SetActive(false);
            }
            var code = info.tipsData["code"].s;
            var content = info.tipsData["content"].s;
            var name = info.conf.notecn;
            var equipment = info.tipsData["equipment"].s;
            var time = info.tipsData["time"].s;

            text.text = $"[{code} {name} {equipment} {content} [报警事件:{time}]]";
            childList[info.tipsData["warnLevelStr"].i - 1].gameObject.SetActive(true);
        }
        
        public void RefreshWithWaringInfo(string info)
        {
            foreach (var tip in childList)
            {
                tip.gameObject.SetActive(false);
            }
            text.gameObject.SetActive(true);
            text.text = info;
        }
    }
}